<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>MODIS L1B数据辐射定标几何校正云掩膜波段合成Python批处理代码实现 | 洛沐の人间客栈</title><meta name="keywords" content="Python卫星数据处理"><meta name="author" content="洛沐,guojiaxiang0820@gmail.com"><meta name="copyright" content="洛沐"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="本文利用Python面向对象编程对MODIS L1B数据进行辐射定标，几何校正，云掩膜以及波段合成等批量数据处理过程。">
<meta property="og:type" content="article">
<meta property="og:title" content="MODIS L1B数据辐射定标几何校正云掩膜波段合成Python批处理代码实现">
<meta property="og:url" content="https://www.guojxblog.cn/archives/58b02e48.html">
<meta property="og:site_name" content="洛沐の人间客栈">
<meta property="og:description" content="本文利用Python面向对象编程对MODIS L1B数据进行辐射定标，几何校正，云掩膜以及波段合成等批量数据处理过程。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/modis_radiometric_geometric_correction/birthday.jpg">
<meta property="article:published_time" content="2023-03-10T14:24:44.000Z">
<meta property="article:modified_time" content="2023-03-13T16:25:30.143Z">
<meta property="article:author" content="洛沐">
<meta property="article:tag" content="Python卫星数据处理">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/modis_radiometric_geometric_correction/birthday.jpg"><link rel="shortcut icon" href="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/RS_icon.jpg"><link rel="canonical" href="https://www.guojxblog.cn/archives/58b02e48"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="baidu-site-verification" content="code-zGPrfnFp7y"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: {"limitDay":180,"position":"top","messagePrev":"此文中创建于","messageNext":"天之前，请以最新文章为准！"},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":500},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: true
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: 洛沐","link":"链接: ","source":"来源: 洛沐の人间客栈","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'mediumZoom',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isAnchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'MODIS L1B数据辐射定标几何校正云掩膜波段合成Python批处理代码实现',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-03-14 00:25:30'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const now = new Date()
          const hour = now.getHours()
          const isNight = hour <= 6 || hour >= 18
          if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
          else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/style.css"><link rel="stylesheet" href="/css/iconfont.css"><link rel="stylesheet" href="/css/font-awesome.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sviptzk/StaticFile_HEXO@latest/butterfly/css/macblack.css"><script src="/live2d-widget/autoload.js"></script><meta name="generator" content="Hexo 6.1.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/touxiang.jpeg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">29</div></a></div><div class="data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">18</div></a></div><div class="data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">7</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa fa-graduation-cap"></i><span> 文章</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa-solid fa-heart-pulse"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/books/"><i class="fa-fw fas fa-book-reader"></i><span> 读书</span></a></li><li><a class="site-page child" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 影视</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa-solid fa-keyboard"></i><span> 动态</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言</span></a></li><li><a class="site-page child" href="/notes/"><i class="fa-fw fas fa-feather-alt"></i><span> 随笔</span></a></li><li><a class="site-page child" href="/ideas/"><i class="fa-fw fa-solid fa-lightbulb"></i><span> 妙想</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/modis_radiometric_geometric_correction/birthday.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">洛沐の人间客栈</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa fa-graduation-cap"></i><span> 文章</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa-solid fa-heart-pulse"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/books/"><i class="fa-fw fas fa-book-reader"></i><span> 读书</span></a></li><li><a class="site-page child" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 影视</span></a></li></ul></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="fa-fw fa-solid fa-keyboard"></i><span> 动态</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言</span></a></li><li><a class="site-page child" href="/notes/"><i class="fa-fw fas fa-feather-alt"></i><span> 随笔</span></a></li><li><a class="site-page child" href="/ideas/"><i class="fa-fw fa-solid fa-lightbulb"></i><span> 妙想</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">MODIS L1B数据辐射定标几何校正云掩膜波段合成Python批处理代码实现</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-03-10T14:24:44.000Z" title="发表于 2023-03-10 22:24:44">2023-03-10</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-03-13T16:25:30.143Z" title="更新于 2023-03-14 00:25:30">2023-03-14</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E7%A8%8B%E5%BA%8F%E4%BB%A3%E7%A0%81/">程序代码</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">3k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>15分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="MODIS L1B数据辐射定标几何校正云掩膜波段合成Python批处理代码实现"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><ul>
<li>本程序主要是对MODIS L1B数据进行辐射定标，几何校正、云掩膜以及波段合成等处理过程；</li>
<li>本程序利用Python面向对象编程实现；</li>
<li>输入路径中需要将MOD02&#x2F;MYD02一级产品数据和MOD35&#x2F;MYD35云掩膜产品数据对应时间位置放入同一路经中。</li>
<li>完整代码已上传至GitHub上：<br><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/guojx0820/MODIS_Radiometric_Geometric_Correction_CloudMask">MODIS_Radiometric_Geometric_Correction_CloudMask</a><h1 id="MODIS-L1B数据波段介绍"><a href="#MODIS-L1B数据波段介绍" class="headerlink" title="MODIS L1B数据波段介绍"></a>MODIS L1B数据波段介绍</h1></li>
</ul>
<p>以下为MODIS数据36个波段介绍：</p>
<ul>
<li>MODIS波段介绍</li>
</ul>
<table>
<thead>
<tr>
<th align="center">波段号</th>
<th align="center">主要应用</th>
<th align="center">分辨率(m)</th>
<th align="center">波段范围(μm)</th>
<th align="center">中心波长</th>
<th align="center">信噪比</th>
</tr>
</thead>
<tbody><tr>
<td align="center">1</td>
<td align="center">植被叶绿素吸收</td>
<td align="center">250</td>
<td align="center">0.620-0.670</td>
<td align="center">0.645</td>
<td align="center">128</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">云和植被覆盖变换</td>
<td align="center">250</td>
<td align="center">0.841-0.876</td>
<td align="center">0.865</td>
<td align="center">201</td>
</tr>
<tr>
<td align="center">3</td>
<td align="center">土壤植被差异</td>
<td align="center">500</td>
<td align="center">0.459-0.479</td>
<td align="center">0.466</td>
<td align="center">243</td>
</tr>
<tr>
<td align="center">4</td>
<td align="center">绿色植被</td>
<td align="center">500</td>
<td align="center">0.545-0.565</td>
<td align="center">0.554</td>
<td align="center">228</td>
</tr>
<tr>
<td align="center">5</td>
<td align="center">叶面&#x2F;树冠差异</td>
<td align="center">500</td>
<td align="center">1.230-0-1.250</td>
<td align="center">1.242</td>
<td align="center">74</td>
</tr>
<tr>
<td align="center">6</td>
<td align="center">雪&#x2F;云差异</td>
<td align="center">500</td>
<td align="center">1.628-1.652</td>
<td align="center">1.629</td>
<td align="center">275</td>
</tr>
<tr>
<td align="center">7</td>
<td align="center">陆地和云的性质</td>
<td align="center">500</td>
<td align="center">2.105-2.155</td>
<td align="center">2.114</td>
<td align="center">110</td>
</tr>
<tr>
<td align="center">8</td>
<td align="center">叶绿素</td>
<td align="center">1000</td>
<td align="center">0.405-0.420</td>
<td align="center">0.412</td>
<td align="center">880</td>
</tr>
<tr>
<td align="center">9</td>
<td align="center">叶绿素</td>
<td align="center">1000</td>
<td align="center">0.438-0.448</td>
<td align="center">0.442</td>
<td align="center">838</td>
</tr>
<tr>
<td align="center">10</td>
<td align="center">叶绿素</td>
<td align="center">1000</td>
<td align="center">0.483-0.493</td>
<td align="center">0.487</td>
<td align="center">802</td>
</tr>
<tr>
<td align="center">11</td>
<td align="center">叶绿素</td>
<td align="center">1000</td>
<td align="center">0.526-0.536</td>
<td align="center">0.530</td>
<td align="center">754</td>
</tr>
<tr>
<td align="center">12</td>
<td align="center">沉淀物</td>
<td align="center">1000</td>
<td align="center">0.546-0.556</td>
<td align="center">0.547</td>
<td align="center">750</td>
</tr>
<tr>
<td align="center">13</td>
<td align="center">沉淀物，大气层</td>
<td align="center">1000</td>
<td align="center">0.662-0.672</td>
<td align="center">0.666</td>
<td align="center">910</td>
</tr>
<tr>
<td align="center">14</td>
<td align="center">叶绿素荧光</td>
<td align="center">1000</td>
<td align="center">0.673-0.683</td>
<td align="center">0.677</td>
<td align="center">1087</td>
</tr>
<tr>
<td align="center">15</td>
<td align="center">气溶胶性质</td>
<td align="center">1000</td>
<td align="center">0.743-0.753</td>
<td align="center">0.747</td>
<td align="center">586</td>
</tr>
<tr>
<td align="center">16</td>
<td align="center">气溶胶&#x2F;大气层性质</td>
<td align="center">1000</td>
<td align="center">0.862-0.877</td>
<td align="center">0.866</td>
<td align="center">516</td>
</tr>
<tr>
<td align="center">17</td>
<td align="center">云&#x2F;大气层性质</td>
<td align="center">1000</td>
<td align="center">0.890-0.920</td>
<td align="center">0.904</td>
<td align="center">167</td>
</tr>
<tr>
<td align="center">18</td>
<td align="center">云&#x2F;大气层性质</td>
<td align="center">1000</td>
<td align="center">0.931-0.941</td>
<td align="center">0.936</td>
<td align="center">57</td>
</tr>
<tr>
<td align="center">19</td>
<td align="center">云&#x2F;大气层性质</td>
<td align="center">1000</td>
<td align="center">0.915-0.965</td>
<td align="center">0.935</td>
<td align="center">250</td>
</tr>
<tr>
<td align="center">20</td>
<td align="center">洋面温度</td>
<td align="center">1000</td>
<td align="center">3.660-3.840</td>
<td align="center">3.785</td>
<td align="center">0.05</td>
</tr>
<tr>
<td align="center">21</td>
<td align="center">森林火灾&#x2F;火山</td>
<td align="center">1000</td>
<td align="center">3.929-3.989</td>
<td align="center">3.992</td>
<td align="center">2</td>
</tr>
<tr>
<td align="center">22</td>
<td align="center">云&#x2F;地表温度</td>
<td align="center">1000</td>
<td align="center">3.929-3.989</td>
<td align="center">3.971</td>
<td align="center">0.07</td>
</tr>
<tr>
<td align="center">23</td>
<td align="center">云&#x2F;地表温度</td>
<td align="center">1000</td>
<td align="center">4.020-4.080</td>
<td align="center">4.056</td>
<td align="center">0.07</td>
</tr>
<tr>
<td align="center">24</td>
<td align="center">对流层温度&#x2F;云片</td>
<td align="center">1000</td>
<td align="center">4.433-4.498</td>
<td align="center">4.473</td>
<td align="center">0.25</td>
</tr>
<tr>
<td align="center">25</td>
<td align="center">对流层温度&#x2F;云片</td>
<td align="center">1000</td>
<td align="center">4.482-4.549</td>
<td align="center">4.545</td>
<td align="center">0.25</td>
</tr>
<tr>
<td align="center">26</td>
<td align="center">红外云探测</td>
<td align="center">1000</td>
<td align="center">1.360-1.390</td>
<td align="center">1.382</td>
<td align="center">150</td>
</tr>
<tr>
<td align="center">27</td>
<td align="center">对流层中层湿度</td>
<td align="center">1000</td>
<td align="center">6.535-6.895</td>
<td align="center">6.766</td>
<td align="center">0.25</td>
</tr>
<tr>
<td align="center">28</td>
<td align="center">对流层中层湿度</td>
<td align="center">1000</td>
<td align="center">7.175-7.475</td>
<td align="center">7.338</td>
<td align="center">0.25</td>
</tr>
<tr>
<td align="center">29</td>
<td align="center">表面温度</td>
<td align="center">1000</td>
<td align="center">8.400-8.700</td>
<td align="center">8.523</td>
<td align="center">0.05</td>
</tr>
<tr>
<td align="center">30</td>
<td align="center">臭氧总量</td>
<td align="center">1000</td>
<td align="center">9.580-9.880</td>
<td align="center">9.730</td>
<td align="center">0.25</td>
</tr>
<tr>
<td align="center">31</td>
<td align="center">云&#x2F;表面温度</td>
<td align="center">1000</td>
<td align="center">10.780-11.280</td>
<td align="center">11.010</td>
<td align="center">0.05</td>
</tr>
<tr>
<td align="center">32</td>
<td align="center">云高和表面温度</td>
<td align="center">1000</td>
<td align="center">11.770-12.270</td>
<td align="center">12.026</td>
<td align="center">0.05</td>
</tr>
<tr>
<td align="center">33</td>
<td align="center">云高和云片</td>
<td align="center">1000</td>
<td align="center">13.185-13.485</td>
<td align="center">13.363</td>
<td align="center">0.25</td>
</tr>
<tr>
<td align="center">34</td>
<td align="center">云高和云片</td>
<td align="center">1000</td>
<td align="center">13.485-13.785</td>
<td align="center">13.681</td>
<td align="center">0.25</td>
</tr>
<tr>
<td align="center">35</td>
<td align="center">云高和云片</td>
<td align="center">1000</td>
<td align="center">13.785-14.085</td>
<td align="center">13.910</td>
<td align="center">0.25</td>
</tr>
<tr>
<td align="center">36</td>
<td align="center">云高和云片</td>
<td align="center">1000</td>
<td align="center">14.085-14.385</td>
<td align="center">14.193</td>
<td align="center">0.35</td>
</tr>
</tbody></table>
<h1 id="Python面向对象编程"><a href="#Python面向对象编程" class="headerlink" title="Python面向对象编程"></a>Python面向对象编程</h1><p>Python面向对象编程与C++类似，主要以类class内方法的实现与互相调用，参数全局化以及实例化对象等内容。以下为类的初始化参数：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">MODIS_Radiometric_Geometric_Correction</span>:</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, l1b_file, cloud_file, out_name</span>):</span><br><span class="line">        self.l1b_file = l1b_file</span><br><span class="line">        self.cloud_file = cloud_file</span><br><span class="line">        self.out_name = out_name</span><br><span class="line">        self.geo_resolution = <span class="number">0.01</span></span><br></pre></td></tr></table></figure>
<h1 id="MODIS-HDF4数据读取"><a href="#MODIS-HDF4数据读取" class="headerlink" title="MODIS HDF4数据读取"></a>MODIS HDF4数据读取</h1><p>以下是MODIS L1B HDF4数据读取，从底层实现的类中方法：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">_read_modis_data_</span>(<span class="params">self</span>):</span><br><span class="line">        modis_l1b = SD(self.l1b_file)</span><br><span class="line">        modis_cloud = SD(self.cloud_file)</span><br><span class="line">        qkm_rad = self._radical_calibration_(modis_l1b, <span class="string">&#x27;EV_250_Aggr1km_RefSB&#x27;</span>, <span class="string">&#x27;radiance_scales&#x27;</span>,</span><br><span class="line">                                             <span class="string">&#x27;radiance_offsets&#x27;</span>)</span><br><span class="line">        hkm_rad = self._radical_calibration_(modis_l1b, <span class="string">&#x27;EV_500_Aggr1km_RefSB&#x27;</span>, <span class="string">&#x27;radiance_scales&#x27;</span>,</span><br><span class="line">                                             <span class="string">&#x27;radiance_offsets&#x27;</span>)</span><br><span class="line">        cloud_data = modis_cloud.select(<span class="string">&#x27;Cloud_Mask&#x27;</span>).get()</span><br><span class="line">        lon = modis_l1b.select(<span class="string">&#x27;Longitude&#x27;</span>).get()</span><br><span class="line">        lat = modis_l1b.select(<span class="string">&#x27;Latitude&#x27;</span>).get()</span><br><span class="line">        <span class="keyword">return</span> qkm_rad, hkm_rad, cloud_data, lon, lat</span><br></pre></td></tr></table></figure>
<h1 id="辐射定标"><a href="#辐射定标" class="headerlink" title="辐射定标"></a>辐射定标</h1><p>读取HDF4数据集中的对象参数，这里的辐射定标是将DN值转化为辐射亮度，也可以转为反射率，只是偏移（offsets）和增益（scales）值不一样，可以在HDF4数据集中找到属性值。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">_radical_calibration_</span>(<span class="params">self, modis_l1b, dataset_name, scales, offsets</span>):</span><br><span class="line">        <span class="built_in">object</span> = modis_l1b.select(dataset_name)</span><br><span class="line">        data = <span class="built_in">object</span>.get()</span><br><span class="line">        scales = <span class="built_in">object</span>.attributes()[scales]</span><br><span class="line">        offsets = <span class="built_in">object</span>.attributes()[offsets]</span><br><span class="line">        data_rad = np.zeros((data.shape[<span class="number">0</span>], data.shape[<span class="number">1</span>], data.shape[<span class="number">2</span>]), dtype=np.float64)</span><br><span class="line">        <span class="keyword">for</span> i_layer <span class="keyword">in</span> <span class="built_in">range</span>(data.shape[<span class="number">0</span>]):</span><br><span class="line">            data_rad[i_layer, :, :] = scales[i_layer] * (data[i_layer, :, :] - offsets[i_layer])</span><br><span class="line">        <span class="keyword">return</span> data_rad</span><br></pre></td></tr></table></figure>
<h1 id="云掩膜"><a href="#云掩膜" class="headerlink" title="云掩膜"></a>云掩膜</h1><p>云掩膜主要是利用MODIS的云掩膜产品MOD35进行处理，将二进制值转化为0，1的二值对L1B图像进行掩膜。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">_cloud_mask_</span>(<span class="params">self, cloud_data</span>):</span><br><span class="line">        cloud_0 = cloud_data[<span class="number">0</span>, :, :]</span><br><span class="line">        cloud_0 = (np.int64(cloud_0 &lt; <span class="number">0</span>) * (<span class="number">256</span> + cloud_0)) + (np.int64(cloud_0 &gt;= <span class="number">0</span>) * cloud_0)</span><br><span class="line">        cloud_binary = np.zeros((cloud_0.shape[<span class="number">0</span>], cloud_0.shape[<span class="number">1</span>], <span class="number">8</span>), dtype=np.int64)</span><br><span class="line">        <span class="keyword">for</span> i_cloud <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">8</span>):</span><br><span class="line">            cloud_binary[:, :, i_cloud] = cloud_0 % <span class="number">2</span></span><br><span class="line">            cloud_0 //= <span class="number">2</span></span><br><span class="line">        clear_result = np.int64(cloud_binary[:, :, <span class="number">0</span>] == <span class="number">1</span>) &amp; np.int64(cloud_binary[:, :, <span class="number">1</span>] == <span class="number">1</span>) \</span><br><span class="line">                       &amp; np.int64(cloud_binary[:, :, <span class="number">2</span>] == <span class="number">1</span>)</span><br><span class="line">        ocean_result = np.int64(cloud_binary[:, :, <span class="number">6</span>] == <span class="number">0</span>) &amp; np.int64(cloud_binary[:, :, <span class="number">7</span>] == <span class="number">0</span>)</span><br><span class="line">        cloud_result = np.int64(clear_result == <span class="number">0</span>) | np.int64(ocean_result == <span class="number">0</span>)</span><br><span class="line">        <span class="keyword">return</span> clear_result</span><br></pre></td></tr></table></figure>
<h1 id="几何校正"><a href="#几何校正" class="headerlink" title="几何校正"></a>几何校正</h1><p>几何校正主要利用读取的经纬度信息，将像元归位，放到其原有的地理位置。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">_georeference_</span>(<span class="params">self, lon, lat, data</span>):</span><br><span class="line">        lon_interp = cv.resize(lon, (data.shape[<span class="number">1</span>], data.shape[<span class="number">0</span>]), interpolation=cv.INTER_LINEAR)</span><br><span class="line">        lat_interp = cv.resize(lat, (data.shape[<span class="number">1</span>], data.shape[<span class="number">0</span>]), interpolation=cv.INTER_LINEAR)</span><br><span class="line">        lon_min = np.<span class="built_in">min</span>(lon_interp)</span><br><span class="line">        lon_max = np.<span class="built_in">max</span>(lon_interp)</span><br><span class="line">        lat_min = np.<span class="built_in">min</span>(lat_interp)</span><br><span class="line">        lat_max = np.<span class="built_in">max</span>(lat_interp)</span><br><span class="line"></span><br><span class="line">        geo_box_col = np.int64(np.ceil((lon_max - lon_min) / self.geo_resolution))</span><br><span class="line">        geo_box_row = np.int64(np.ceil((lat_max - lat_min) / self.geo_resolution))</span><br><span class="line">        geo_box = np.zeros((geo_box_row, geo_box_col), dtype=np.float64)</span><br><span class="line">        geo_box_col_pos = np.int64(np.floor((lon_interp - lon_min) / self.geo_resolution))</span><br><span class="line">        geo_box_row_pos = np.int64(np.floor((lat_max - lat_interp) / self.geo_resolution))</span><br><span class="line">        geo_box[geo_box_row_pos, geo_box_col_pos] = data</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> geo_box, lon_min, lat_max</span><br></pre></td></tr></table></figure>
<h1 id="均值平滑像元填补"><a href="#均值平滑像元填补" class="headerlink" title="均值平滑像元填补"></a>均值平滑像元填补</h1><p>由于几何纠正之后影像上会有大量像元值空缺，所以利用窗口均值平滑的方法尽可能进行填补，以确保图像部分连续。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">_average_filtering_</span>(<span class="params">self, geo_box</span>):</span><br><span class="line">        geo_box_plus = np.zeros((geo_box.shape[<span class="number">0</span>] + <span class="number">2</span>, geo_box.shape[<span class="number">1</span>] + <span class="number">2</span>), dtype=np.float64) - <span class="number">9999.0</span></span><br><span class="line">        geo_box_plus[<span class="number">1</span>:geo_box.shape[<span class="number">0</span>] + <span class="number">1</span>, <span class="number">1</span>:geo_box.shape[<span class="number">1</span>] + <span class="number">1</span>] = geo_box</span><br><span class="line">        geo_box_out = np.zeros((geo_box.shape[<span class="number">0</span>], geo_box.shape[<span class="number">1</span>]), dtype=np.float64)</span><br><span class="line">        <span class="keyword">for</span> i_geo_box_row <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, geo_box.shape[<span class="number">0</span>] + <span class="number">1</span>):</span><br><span class="line">            <span class="keyword">for</span> i_geo_box_col <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, geo_box.shape[<span class="number">1</span>] + <span class="number">1</span>):</span><br><span class="line">                <span class="keyword">if</span> geo_box_plus[i_geo_box_row, i_geo_box_col] == <span class="number">0.0</span>:</span><br><span class="line">                    temp_window = geo_box_plus[i_geo_box_row - <span class="number">1</span>:i_geo_box_row + <span class="number">2</span>,</span><br><span class="line">                                  i_geo_box_col - <span class="number">1</span>:i_geo_box_col + <span class="number">2</span>]</span><br><span class="line">                    temp_window = temp_window[temp_window &gt; <span class="number">0</span>]</span><br><span class="line">                    temp_window_sum = np.<span class="built_in">sum</span>(temp_window)</span><br><span class="line">                    temp_window_num = np.<span class="built_in">sum</span>(np.int64(temp_window &gt; <span class="number">0.0</span>))</span><br><span class="line">                    <span class="keyword">if</span> temp_window_num &gt; <span class="number">3</span>:</span><br><span class="line">                        geo_box_out[i_geo_box_row - <span class="number">1</span>, i_geo_box_col - <span class="number">1</span>] = temp_window_sum / temp_window_num</span><br><span class="line">                    <span class="keyword">else</span>:</span><br><span class="line">                        geo_box_out[i_geo_box_row - <span class="number">1</span>, i_geo_box_col - <span class="number">1</span>] = <span class="number">0.0</span></span><br><span class="line">                <span class="keyword">else</span>:</span><br><span class="line">                    geo_box_out[i_geo_box_row - <span class="number">1</span>, i_geo_box_col - <span class="number">1</span>] = geo_box_plus[</span><br><span class="line">                        i_geo_box_row, i_geo_box_col]</span><br><span class="line">        <span class="keyword">return</span> geo_box_out</span><br></pre></td></tr></table></figure>
<h1 id="B、G、R和NIR波段提取"><a href="#B、G、R和NIR波段提取" class="headerlink" title="B、G、R和NIR波段提取"></a>B、G、R和NIR波段提取</h1><p>分别将MODIS上述波段1，2，3，4分别对应红（R），近红外（NIR），蓝（B），绿（G）四个波段提取出来并按照B、G、R、NIR的顺序排列，并储存在一个数组中。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">_band_extract_</span>(<span class="params">self, lon, lat, qkm_rad, hkm_rad, clear_result</span>):</span><br><span class="line">        blue_band = hkm_rad[<span class="number">0</span>] * clear_result</span><br><span class="line">        green_band = hkm_rad[<span class="number">1</span>] * clear_result</span><br><span class="line">        red_band = qkm_rad[<span class="number">0</span>] * clear_result</span><br><span class="line">        nir_band = qkm_rad[<span class="number">1</span>] * clear_result</span><br><span class="line">        com_bands = np.array([blue_band, green_band, red_band, nir_band])</span><br><span class="line">        band_list = []</span><br><span class="line">        <span class="keyword">for</span> i_band <span class="keyword">in</span> com_bands:</span><br><span class="line">            geo_band, lon_min, lat_max = self._georeference_(lon, lat, i_band)</span><br><span class="line">            filter_band = self._average_filtering_(geo_band)</span><br><span class="line">            band_list.append(filter_band)</span><br><span class="line">        band_arr = np.array(band_list)</span><br><span class="line">        <span class="keyword">return</span> band_arr, lon_min, lat_max</span><br></pre></td></tr></table></figure>
<h1 id="GDAL波段合成与输出"><a href="#GDAL波段合成与输出" class="headerlink" title="GDAL波段合成与输出"></a>GDAL波段合成与输出</h1><p>利用GDAL写入图像的投影信息，仿射变换信息，以及对上述四个波段按顺序合成并保存到硬盘。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">_write_tiff_</span>(<span class="params">self, data, lon_min, lat_max</span>):</span><br><span class="line">        cols = data.shape[<span class="number">2</span>]</span><br><span class="line">        rows = data.shape[<span class="number">1</span>]</span><br><span class="line">        band_count = data.shape[<span class="number">0</span>]</span><br><span class="line">        driver = gdal.GetDriverByName(<span class="string">&#x27;GTiff&#x27;</span>)</span><br><span class="line">        out_raster = driver.Create(self.out_name, cols, rows, band_count, gdal.GDT_Float64)</span><br><span class="line"></span><br><span class="line">        out_raster.SetGeoTransform((lon_min, self.geo_resolution, <span class="number">0</span>, lat_max, <span class="number">0</span>, self.geo_resolution))</span><br><span class="line">        out_raster_SRS = osr.SpatialReference()</span><br><span class="line">        <span class="comment"># 代码4326表示WGS84坐标</span></span><br><span class="line">        out_raster_SRS.ImportFromEPSG(<span class="number">4326</span>)</span><br><span class="line">        out_raster.SetProjection(out_raster_SRS.ExportToWkt())</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 获取数据集第一个波段，是从1开始，不是从0开始</span></span><br><span class="line">        <span class="keyword">for</span> i_band_count <span class="keyword">in</span> <span class="built_in">range</span>(band_count):</span><br><span class="line">            out_raster.GetRasterBand(i_band_count + <span class="number">1</span>).WriteArray(data[i_band_count])</span><br><span class="line">        out_raster.FlushCache()</span><br><span class="line">        out_raster = <span class="literal">None</span></span><br></pre></td></tr></table></figure>
<h1 id="Python批量读取与数据匹配"><a href="#Python批量读取与数据匹配" class="headerlink" title="Python批量读取与数据匹配"></a>Python批量读取与数据匹配</h1><p>这里是主程序，主要功能是搜索文件路径，并读取匹配MOD02 L1B数据和MOD35 CloudMask数据，并定义初始化输入输出文件路径，批处理数据，实例化对象，函数调用以及计算处理时间。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    start_time = time.time()</span><br><span class="line">    input_directory = <span class="string">&#x27;/mnt/e/Experiments/AOD_Retrieval/DATA/MOD021KM_MOD35Cloud_202205/&#x27;</span></span><br><span class="line">    output_directory = <span class="string">&#x27;/mnt/e/Experiments/AOD_Retrieval/DATA/Results/Results_MOD021KM_Rad_Geo_Cal/&#x27;</span></span><br><span class="line">    <span class="keyword">if</span> os.path.exists(output_directory) == <span class="literal">False</span>:</span><br><span class="line">        os.makedirs(output_directory)</span><br><span class="line">    <span class="keyword">for</span> root, dirs, files <span class="keyword">in</span> os.walk(input_directory):</span><br><span class="line">        l1b_file_list = [input_directory + i_hdf <span class="keyword">for</span> i_hdf <span class="keyword">in</span> files <span class="keyword">if</span></span><br><span class="line">                         i_hdf.endswith(<span class="string">&#x27;.hdf&#x27;</span>) <span class="keyword">and</span> i_hdf.startswith(<span class="string">&#x27;MOD02&#x27;</span>)]</span><br><span class="line">        cloud_file_list = [input_directory + i_hdf <span class="keyword">for</span> i_hdf <span class="keyword">in</span> files <span class="keyword">if</span></span><br><span class="line">                           i_hdf.endswith(<span class="string">&#x27;.hdf&#x27;</span>) <span class="keyword">and</span> i_hdf.startswith(<span class="string">&#x27;MOD35&#x27;</span>)]</span><br><span class="line">    <span class="keyword">for</span> i_l1b <span class="keyword">in</span> l1b_file_list:</span><br><span class="line">        <span class="keyword">for</span> i_cloud <span class="keyword">in</span> cloud_file_list:</span><br><span class="line">            <span class="keyword">if</span> os.path.basename(i_l1b)[<span class="number">10</span>:<span class="number">22</span>] == os.path.basename(i_cloud)[<span class="number">10</span>:<span class="number">22</span>]:</span><br><span class="line">                start_time_each = time.time()</span><br><span class="line">                out_name = output_directory + os.path.basename(i_l1b[:-<span class="number">4</span>]) + <span class="string">&#x27;_Rad_Geo_Cor.tiff&#x27;</span></span><br><span class="line">                modis_rad_geo_cor = MODIS_Radiometric_Geometric_Correction(i_l1b, i_cloud, out_name)</span><br><span class="line">                qkm_rad, hkm_rad, cloud_data, lon, lat = modis_rad_geo_cor._read_modis_data_()</span><br><span class="line">                clear_result = modis_rad_geo_cor._cloud_mask_(cloud_data)</span><br><span class="line">                com_band, lon_min, lat_max = modis_rad_geo_cor._band_extract_(lon, lat, qkm_rad, hkm_rad, clear_result)</span><br><span class="line">                modis_rad_geo_cor._write_tiff_(com_band, lon_min, lat_max)</span><br><span class="line"></span><br><span class="line">                end_time_each = time.time()</span><br><span class="line">                run_time_each = <span class="built_in">round</span>(end_time_each - start_time_each, <span class="number">3</span>)</span><br><span class="line">                <span class="built_in">print</span>(<span class="string">&#x27;The image of &#x27;</span> + os.path.basename(i_l1b)[<span class="number">10</span>:<span class="number">22</span>] + <span class="string">&#x27; is saved! The time consuming is &#x27;</span> + <span class="built_in">str</span>(</span><br><span class="line">                    run_time_each) + <span class="string">&#x27; s.&#x27;</span>)</span><br><span class="line">    end_time = time.time()</span><br><span class="line">    run_time = <span class="built_in">round</span>(end_time - start_time, <span class="number">3</span>)</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&#x27;The total time consuming is &#x27;</span> + <span class="built_in">str</span>(run_time) + <span class="string">&#x27; s.&#x27;</span>)</span><br></pre></td></tr></table></figure>

<h1 id="完整代码"><a href="#完整代码" class="headerlink" title="完整代码"></a>完整代码</h1><p>以下是完整代码：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">from</span> osgeo <span class="keyword">import</span> gdal, osr</span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">from</span> pyhdf.SD <span class="keyword">import</span> SD</span><br><span class="line"><span class="keyword">import</span> cv2 <span class="keyword">as</span> cv</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">MODIS_Radiometric_Geometric_Correction</span>:</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, l1b_file, cloud_file, out_name</span>):</span><br><span class="line">        self.l1b_file = l1b_file</span><br><span class="line">        self.cloud_file = cloud_file</span><br><span class="line">        self.out_name = out_name</span><br><span class="line">        self.geo_resolution = <span class="number">0.01</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">_read_modis_data_</span>(<span class="params">self</span>):</span><br><span class="line">        modis_l1b = SD(self.l1b_file)</span><br><span class="line">        modis_cloud = SD(self.cloud_file)</span><br><span class="line">        qkm_rad = self._radical_calibration_(modis_l1b, <span class="string">&#x27;EV_250_Aggr1km_RefSB&#x27;</span>, <span class="string">&#x27;radiance_scales&#x27;</span>,</span><br><span class="line">                                             <span class="string">&#x27;radiance_offsets&#x27;</span>)</span><br><span class="line">        hkm_rad = self._radical_calibration_(modis_l1b, <span class="string">&#x27;EV_500_Aggr1km_RefSB&#x27;</span>, <span class="string">&#x27;radiance_scales&#x27;</span>,</span><br><span class="line">                                             <span class="string">&#x27;radiance_offsets&#x27;</span>)</span><br><span class="line">        cloud_data = modis_cloud.select(<span class="string">&#x27;Cloud_Mask&#x27;</span>).get()</span><br><span class="line">        lon = modis_l1b.select(<span class="string">&#x27;Longitude&#x27;</span>).get()</span><br><span class="line">        lat = modis_l1b.select(<span class="string">&#x27;Latitude&#x27;</span>).get()</span><br><span class="line">        <span class="keyword">return</span> qkm_rad, hkm_rad, cloud_data, lon, lat</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">_radical_calibration_</span>(<span class="params">self, modis_l1b, dataset_name, scales, offsets</span>):</span><br><span class="line">        <span class="built_in">object</span> = modis_l1b.select(dataset_name)</span><br><span class="line">        data = <span class="built_in">object</span>.get()</span><br><span class="line">        scales = <span class="built_in">object</span>.attributes()[scales]</span><br><span class="line">        offsets = <span class="built_in">object</span>.attributes()[offsets]</span><br><span class="line">        data_rad = np.zeros((data.shape[<span class="number">0</span>], data.shape[<span class="number">1</span>], data.shape[<span class="number">2</span>]), dtype=np.float64)</span><br><span class="line">        <span class="keyword">for</span> i_layer <span class="keyword">in</span> <span class="built_in">range</span>(data.shape[<span class="number">0</span>]):</span><br><span class="line">            data_rad[i_layer, :, :] = scales[i_layer] * (data[i_layer, :, :] - offsets[i_layer])</span><br><span class="line">        <span class="keyword">return</span> data_rad</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">_cloud_mask_</span>(<span class="params">self, cloud_data</span>):</span><br><span class="line">        cloud_0 = cloud_data[<span class="number">0</span>, :, :]</span><br><span class="line">        cloud_0 = (np.int64(cloud_0 &lt; <span class="number">0</span>) * (<span class="number">256</span> + cloud_0)) + (np.int64(cloud_0 &gt;= <span class="number">0</span>) * cloud_0)</span><br><span class="line">        cloud_binary = np.zeros((cloud_0.shape[<span class="number">0</span>], cloud_0.shape[<span class="number">1</span>], <span class="number">8</span>), dtype=np.int64)</span><br><span class="line">        <span class="keyword">for</span> i_cloud <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">8</span>):</span><br><span class="line">            cloud_binary[:, :, i_cloud] = cloud_0 % <span class="number">2</span></span><br><span class="line">            cloud_0 //= <span class="number">2</span></span><br><span class="line">        clear_result = np.int64(cloud_binary[:, :, <span class="number">0</span>] == <span class="number">1</span>) &amp; np.int64(cloud_binary[:, :, <span class="number">1</span>] == <span class="number">1</span>) \</span><br><span class="line">                       &amp; np.int64(cloud_binary[:, :, <span class="number">2</span>] == <span class="number">1</span>)</span><br><span class="line">        ocean_result = np.int64(cloud_binary[:, :, <span class="number">6</span>] == <span class="number">0</span>) &amp; np.int64(cloud_binary[:, :, <span class="number">7</span>] == <span class="number">0</span>)</span><br><span class="line">        cloud_result = np.int64(clear_result == <span class="number">0</span>) | np.int64(ocean_result == <span class="number">0</span>)</span><br><span class="line">        <span class="keyword">return</span> clear_result</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">_band_extract_</span>(<span class="params">self, lon, lat, qkm_rad, hkm_rad, clear_result</span>):</span><br><span class="line">        blue_band = hkm_rad[<span class="number">0</span>] * clear_result</span><br><span class="line">        green_band = hkm_rad[<span class="number">1</span>] * clear_result</span><br><span class="line">        red_band = qkm_rad[<span class="number">0</span>] * clear_result</span><br><span class="line">        nir_band = qkm_rad[<span class="number">1</span>] * clear_result</span><br><span class="line">        com_bands = np.array([blue_band, green_band, red_band, nir_band])</span><br><span class="line">        band_list = []</span><br><span class="line">        <span class="keyword">for</span> i_band <span class="keyword">in</span> com_bands:</span><br><span class="line">            geo_band, lon_min, lat_max = self._georeference_(lon, lat, i_band)</span><br><span class="line">            filter_band = self._average_filtering_(geo_band)</span><br><span class="line">            band_list.append(filter_band)</span><br><span class="line">        band_arr = np.array(band_list)</span><br><span class="line">        <span class="keyword">return</span> band_arr, lon_min, lat_max</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">_georeference_</span>(<span class="params">self, lon, lat, data</span>):</span><br><span class="line">        lon_interp = cv.resize(lon, (data.shape[<span class="number">1</span>], data.shape[<span class="number">0</span>]), interpolation=cv.INTER_LINEAR)</span><br><span class="line">        lat_interp = cv.resize(lat, (data.shape[<span class="number">1</span>], data.shape[<span class="number">0</span>]), interpolation=cv.INTER_LINEAR)</span><br><span class="line">        lon_min = np.<span class="built_in">min</span>(lon_interp)</span><br><span class="line">        lon_max = np.<span class="built_in">max</span>(lon_interp)</span><br><span class="line">        lat_min = np.<span class="built_in">min</span>(lat_interp)</span><br><span class="line">        lat_max = np.<span class="built_in">max</span>(lat_interp)</span><br><span class="line"></span><br><span class="line">        geo_box_col = np.int64(np.ceil((lon_max - lon_min) / self.geo_resolution))</span><br><span class="line">        geo_box_row = np.int64(np.ceil((lat_max - lat_min) / self.geo_resolution))</span><br><span class="line">        geo_box = np.zeros((geo_box_row, geo_box_col), dtype=np.float64)</span><br><span class="line">        geo_box_col_pos = np.int64(np.floor((lon_interp - lon_min) / self.geo_resolution))</span><br><span class="line">        geo_box_row_pos = np.int64(np.floor((lat_max - lat_interp) / self.geo_resolution))</span><br><span class="line">        geo_box[geo_box_row_pos, geo_box_col_pos] = data</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> geo_box, lon_min, lat_max</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">_average_filtering_</span>(<span class="params">self, geo_box</span>):</span><br><span class="line">        geo_box_plus = np.zeros((geo_box.shape[<span class="number">0</span>] + <span class="number">2</span>, geo_box.shape[<span class="number">1</span>] + <span class="number">2</span>), dtype=np.float64) - <span class="number">9999.0</span></span><br><span class="line">        geo_box_plus[<span class="number">1</span>:geo_box.shape[<span class="number">0</span>] + <span class="number">1</span>, <span class="number">1</span>:geo_box.shape[<span class="number">1</span>] + <span class="number">1</span>] = geo_box</span><br><span class="line">        geo_box_out = np.zeros((geo_box.shape[<span class="number">0</span>], geo_box.shape[<span class="number">1</span>]), dtype=np.float64)</span><br><span class="line">        <span class="keyword">for</span> i_geo_box_row <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, geo_box.shape[<span class="number">0</span>] + <span class="number">1</span>):</span><br><span class="line">            <span class="keyword">for</span> i_geo_box_col <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>, geo_box.shape[<span class="number">1</span>] + <span class="number">1</span>):</span><br><span class="line">                <span class="keyword">if</span> geo_box_plus[i_geo_box_row, i_geo_box_col] == <span class="number">0.0</span>:</span><br><span class="line">                    temp_window = geo_box_plus[i_geo_box_row - <span class="number">1</span>:i_geo_box_row + <span class="number">2</span>,</span><br><span class="line">                                  i_geo_box_col - <span class="number">1</span>:i_geo_box_col + <span class="number">2</span>]</span><br><span class="line">                    temp_window = temp_window[temp_window &gt; <span class="number">0</span>]</span><br><span class="line">                    temp_window_sum = np.<span class="built_in">sum</span>(temp_window)</span><br><span class="line">                    temp_window_num = np.<span class="built_in">sum</span>(np.int64(temp_window &gt; <span class="number">0.0</span>))</span><br><span class="line">                    <span class="keyword">if</span> temp_window_num &gt; <span class="number">3</span>:</span><br><span class="line">                        geo_box_out[i_geo_box_row - <span class="number">1</span>, i_geo_box_col - <span class="number">1</span>] = temp_window_sum / temp_window_num</span><br><span class="line">                    <span class="keyword">else</span>:</span><br><span class="line">                        geo_box_out[i_geo_box_row - <span class="number">1</span>, i_geo_box_col - <span class="number">1</span>] = <span class="number">0.0</span></span><br><span class="line">                <span class="keyword">else</span>:</span><br><span class="line">                    geo_box_out[i_geo_box_row - <span class="number">1</span>, i_geo_box_col - <span class="number">1</span>] = geo_box_plus[</span><br><span class="line">                        i_geo_box_row, i_geo_box_col]</span><br><span class="line">        <span class="keyword">return</span> geo_box_out</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">_write_tiff_</span>(<span class="params">self, data, lon_min, lat_max</span>):</span><br><span class="line">        cols = data.shape[<span class="number">2</span>]</span><br><span class="line">        rows = data.shape[<span class="number">1</span>]</span><br><span class="line">        band_count = data.shape[<span class="number">0</span>]</span><br><span class="line">        driver = gdal.GetDriverByName(<span class="string">&#x27;GTiff&#x27;</span>)</span><br><span class="line">        out_raster = driver.Create(self.out_name, cols, rows, band_count, gdal.GDT_Float64)</span><br><span class="line"></span><br><span class="line">        out_raster.SetGeoTransform((lon_min, self.geo_resolution, <span class="number">0</span>, lat_max, <span class="number">0</span>, self.geo_resolution))</span><br><span class="line">        out_raster_SRS = osr.SpatialReference()</span><br><span class="line">        <span class="comment"># 代码4326表示WGS84坐标</span></span><br><span class="line">        out_raster_SRS.ImportFromEPSG(<span class="number">4326</span>)</span><br><span class="line">        out_raster.SetProjection(out_raster_SRS.ExportToWkt())</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 获取数据集第一个波段，是从1开始，不是从0开始</span></span><br><span class="line">        <span class="keyword">for</span> i_band_count <span class="keyword">in</span> <span class="built_in">range</span>(band_count):</span><br><span class="line">            out_raster.GetRasterBand(i_band_count + <span class="number">1</span>).WriteArray(data[i_band_count])</span><br><span class="line">        out_raster.FlushCache()</span><br><span class="line">        out_raster = <span class="literal">None</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    start_time = time.time()</span><br><span class="line">    input_directory = <span class="string">&#x27;/mnt/e/Experiments/AOD_Retrieval/DATA/MOD021KM_MOD35Cloud_202205/&#x27;</span></span><br><span class="line">    output_directory = <span class="string">&#x27;/mnt/e/Experiments/AOD_Retrieval/DATA/Results/Results_MOD021KM_Rad_Geo_Cal/&#x27;</span></span><br><span class="line">    <span class="keyword">if</span> os.path.exists(output_directory) == <span class="literal">False</span>:</span><br><span class="line">        os.makedirs(output_directory)</span><br><span class="line">    <span class="keyword">for</span> root, dirs, files <span class="keyword">in</span> os.walk(input_directory):</span><br><span class="line">        l1b_file_list = [input_directory + i_hdf <span class="keyword">for</span> i_hdf <span class="keyword">in</span> files <span class="keyword">if</span></span><br><span class="line">                         i_hdf.endswith(<span class="string">&#x27;.hdf&#x27;</span>) <span class="keyword">and</span> i_hdf.startswith(<span class="string">&#x27;MOD02&#x27;</span>)]</span><br><span class="line">        cloud_file_list = [input_directory + i_hdf <span class="keyword">for</span> i_hdf <span class="keyword">in</span> files <span class="keyword">if</span></span><br><span class="line">                           i_hdf.endswith(<span class="string">&#x27;.hdf&#x27;</span>) <span class="keyword">and</span> i_hdf.startswith(<span class="string">&#x27;MOD35&#x27;</span>)]</span><br><span class="line">    <span class="keyword">for</span> i_l1b <span class="keyword">in</span> l1b_file_list:</span><br><span class="line">        <span class="keyword">for</span> i_cloud <span class="keyword">in</span> cloud_file_list:</span><br><span class="line">            <span class="keyword">if</span> os.path.basename(i_l1b)[<span class="number">10</span>:<span class="number">22</span>] == os.path.basename(i_cloud)[<span class="number">10</span>:<span class="number">22</span>]:</span><br><span class="line">                start_time_each = time.time()</span><br><span class="line">                out_name = output_directory + os.path.basename(i_l1b[:-<span class="number">4</span>]) + <span class="string">&#x27;_Rad_Geo_Cor.tiff&#x27;</span></span><br><span class="line">                modis_rad_geo_cor = MODIS_Radiometric_Geometric_Correction(i_l1b, i_cloud, out_name)</span><br><span class="line">                qkm_rad, hkm_rad, cloud_data, lon, lat = modis_rad_geo_cor._read_modis_data_()</span><br><span class="line">                clear_result = modis_rad_geo_cor._cloud_mask_(cloud_data)</span><br><span class="line">                com_band, lon_min, lat_max = modis_rad_geo_cor._band_extract_(lon, lat, qkm_rad, hkm_rad, clear_result)</span><br><span class="line">                modis_rad_geo_cor._write_tiff_(com_band, lon_min, lat_max)</span><br><span class="line"></span><br><span class="line">                end_time_each = time.time()</span><br><span class="line">                run_time_each = <span class="built_in">round</span>(end_time_each - start_time_each, <span class="number">3</span>)</span><br><span class="line">                <span class="built_in">print</span>(<span class="string">&#x27;The image of &#x27;</span> + os.path.basename(i_l1b)[<span class="number">10</span>:<span class="number">22</span>] + <span class="string">&#x27; is saved! The time consuming is &#x27;</span> + <span class="built_in">str</span>(</span><br><span class="line">                    run_time_each) + <span class="string">&#x27; s.&#x27;</span>)</span><br><span class="line">    end_time = time.time()</span><br><span class="line">    run_time = <span class="built_in">round</span>(end_time - start_time, <span class="number">3</span>)</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&#x27;The total time consuming is &#x27;</span> + <span class="built_in">str</span>(run_time) + <span class="string">&#x27; s.&#x27;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h1 id="运行结果"><a href="#运行结果" class="headerlink" title="运行结果"></a>运行结果</h1><p>下图分别为MODIS合成的真彩色和彩红外影像。</p>
<p>真彩色合成是对MODIS合成数据B（1）、G（2）、R（3）、NIR（4）四个波段按照R（3）、G（2）、B（1）分别赋红、绿、蓝三种颜色显示出与真实色彩一致的影像合成方法。</p>
<p><img src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/modis_radiometric_geometric_correction/modis_rgb.jpg" alt="MODIS 真彩色合成影像"></p>
<p>彩红外又叫标准假彩色合成，是对MODIS合成数据B（1）、G（2）、R（3）、NIR（4）四个波段按照NIR（4）、R（3）、G（2）分别赋红、绿、蓝三种颜色显示出与真实色彩不一致但能突出影像上的水体植被特征的一种遥感影像合成方法（植被显红色，水体显黑色）。</p>
<p><img src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/modis_radiometric_geometric_correction/modis_colorIr.jpg" alt="MODIS 彩红外合成影像"></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:guojiaxiang0820@gmail.com" rel="external nofollow noreferrer">洛沐</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.guojxblog.cn/archives/58b02e48.html">https://www.guojxblog.cn/archives/58b02e48.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noreferrer" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.guojxblog.cn" target="_blank">洛沐の人间客栈</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Python%E5%8D%AB%E6%98%9F%E6%95%B0%E6%8D%AE%E5%A4%84%E7%90%86/">Python卫星数据处理</a></div><div class="post_share"><div class="social-share" data-image="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/modis_radiometric_geometric_correction/birthday.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/wechat.jpeg" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/wechat.jpeg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/alipay.jpeg" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/alipay.jpeg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/archives/59a3b95f.html"><img class="prev-cover" src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/Jason-3SSHA/lulu.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Jason-3SSHA数据处理与可视化——Python代码实现</div></div></a></div><div class="next-post pull-right"><a href="/archives/b7563557.html"><img class="next-cover" src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/AerosolClassification/WhaleSkeleton.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">气溶胶遥感分类方法</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/archives/92a27152.html" title="GMI降雨率数据Hovmoller纬向显示——Python代码实现"><img class="cover" src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/GMI_RainRate/smile.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-20</div><div class="title">GMI降雨率数据Hovmoller纬向显示——Python代码实现</div></div></a></div><div><a href="/archives/59a3b95f.html" title="Jason-3SSHA数据处理与可视化——Python代码实现"><img class="cover" src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/Jason-3SSHA/lulu.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-12</div><div class="title">Jason-3SSHA数据处理与可视化——Python代码实现</div></div></a></div><div><a href="/archives/b9d5eb5f.html" title="SMAP海洋表面盐度（SSS）数据可视化——Python实现"><img class="cover" src="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/loading3.gif" data-original="https://luomublog.oss-cn-qingdao.aliyuncs.com/ImgHost/Smap_SSS/loli.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-25</div><div class="title">SMAP海洋表面盐度（SSS）数据可视化——Python实现</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="lv-container" data-id="city" data-uid="MTAyMC81NjIzOS8zMjcwMg=="></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#MODIS-L1B%E6%95%B0%E6%8D%AE%E6%B3%A2%E6%AE%B5%E4%BB%8B%E7%BB%8D"><span class="toc-number">1.</span> <span class="toc-text">MODIS L1B数据波段介绍</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Python%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B"><span class="toc-number">2.</span> <span class="toc-text">Python面向对象编程</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#MODIS-HDF4%E6%95%B0%E6%8D%AE%E8%AF%BB%E5%8F%96"><span class="toc-number">3.</span> <span class="toc-text">MODIS HDF4数据读取</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%BE%90%E5%B0%84%E5%AE%9A%E6%A0%87"><span class="toc-number">4.</span> <span class="toc-text">辐射定标</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%91%E6%8E%A9%E8%86%9C"><span class="toc-number">5.</span> <span class="toc-text">云掩膜</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%87%A0%E4%BD%95%E6%A0%A1%E6%AD%A3"><span class="toc-number">6.</span> <span class="toc-text">几何校正</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9D%87%E5%80%BC%E5%B9%B3%E6%BB%91%E5%83%8F%E5%85%83%E5%A1%AB%E8%A1%A5"><span class="toc-number">7.</span> <span class="toc-text">均值平滑像元填补</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#B%E3%80%81G%E3%80%81R%E5%92%8CNIR%E6%B3%A2%E6%AE%B5%E6%8F%90%E5%8F%96"><span class="toc-number">8.</span> <span class="toc-text">B、G、R和NIR波段提取</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#GDAL%E6%B3%A2%E6%AE%B5%E5%90%88%E6%88%90%E4%B8%8E%E8%BE%93%E5%87%BA"><span class="toc-number">9.</span> <span class="toc-text">GDAL波段合成与输出</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Python%E6%89%B9%E9%87%8F%E8%AF%BB%E5%8F%96%E4%B8%8E%E6%95%B0%E6%8D%AE%E5%8C%B9%E9%85%8D"><span class="toc-number">10.</span> <span class="toc-text">Python批量读取与数据匹配</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AE%8C%E6%95%B4%E4%BB%A3%E7%A0%81"><span class="toc-number">11.</span> <span class="toc-text">完整代码</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%BF%90%E8%A1%8C%E7%BB%93%E6%9E%9C"><span class="toc-number">12.</span> <span class="toc-text">运行结果</span></a></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2023  <i id="heartbeat" class="fa fas fa-heartbeat"></i> 洛沐</div><div class="footer_custom_text">谢谢你来看<a href="https://www.guojxblog.cn/" style='color:red;Font-size:36'>我</a>，你今天真好看😘</div></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/HCLonely/images@master/others/heartbeat.min.css"></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">簡</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">本地搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>function loadLivere () {
  if (typeof LivereTower === 'object') {
    window.LivereTower.init()
  }
  else {
    (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
    })(document, 'script');
  }
}

if ('Livere' === 'Livere' || !true) {
  if (true) btf.loadComment(document.getElementById('lv-container'), loadLivere)
  else loadLivere()
}
else {
  function loadOtherComment () {
    loadLivere()
  }
}</script></div><script src="/js/mobile_side.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script><div class="pjax-reload"><script async="async">var arr = document.getElementsByClassName('recent-post-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '1s');
    arr[i].setAttribute('data-wow-delay', '700ms');
    arr[i].setAttribute('data-wow-offset', '100');
    arr[i].setAttribute('data-wow-iteration', '1');
}</script><script async="async">var arr = document.getElementsByClassName('card-widget');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
}</script></div><script defer="defer" src="https://cdn.jsdelivr.net/gh/graingert/wow@1.3.0/dist/wow.min.js"></script><script defer="defer" src="/js/wow_init.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script>
            window.imageLazyLoadSetting = {
                isSPA: true,
                preloadRatio: 3,
                processImages: null,
            };
        </script><script>window.addEventListener("load",function(){var t=/\.(gif|jpg|jpeg|tiff|png)$/i,r=/^data:image\/[a-z]+;base64,/;Array.prototype.slice.call(document.querySelectorAll("img[data-original]")).forEach(function(a){var e=a.parentNode;"A"===e.tagName&&(e.href.match(t)||e.href.match(r))&&(e.href=a.dataset.original)})});</script><script>!function(n){n.imageLazyLoadSetting.processImages=o;var e=n.imageLazyLoadSetting.isSPA,i=n.imageLazyLoadSetting.preloadRatio||1,r=Array.prototype.slice.call(document.querySelectorAll("img[data-original]"));function o(){e&&(r=Array.prototype.slice.call(document.querySelectorAll("img[data-original]")));for(var t,a=0;a<r.length;a++)0<=(t=(t=r[a]).getBoundingClientRect()).bottom&&0<=t.left&&t.top<=(n.innerHeight*i||document.documentElement.clientHeight*i)&&function(){var t,e,n,i,o=r[a];t=o,e=function(){r=r.filter(function(t){return o!==t})},n=new Image,i=t.getAttribute("data-original"),n.onload=function(){t.src=i,e&&e()},t.src!==i&&(n.src=i)}()}o(),n.addEventListener("scroll",function(){var t,e;t=o,e=n,clearTimeout(t.tId),t.tId=setTimeout(function(){t.call(e)},500)})}(this);</script><script async>window.onload=function(){var a=document.createElement('script'),b=document.getElementsByTagName('script')[0];a.type='text/javascript',a.async=!0,a.src='/sw-register.js?v='+Date.now(),b.parentNode.insertBefore(a,b)};</script></body></html>